package tk.mybatis.springboot.mapper.Provider;

import java.util.Map;

import org.apache.ibatis.jdbc.SQL;

public class LeavingmessageProvider {
	public String findLeavingmessageList(final Map<String, Object> params) {
		return new SQL(){{
			SELECT("lm.*, t.nickname as userName");
			FROM("leavingmessage lm");
			LEFT_OUTER_JOIN("t_user t on lm.userid = t.id");
			if(params.get("contextDateBegin") != null){
				WHERE("lm.createdate > #{contextDateBegin}");
			}
			if(params.get("contextDateEnd") != null){
				WHERE("lm.createdate < #{contextDateEnd}");
			}
			if(params.get("userName") != null){
				WHERE("t.nickname = #{userName}");
			}
			if(params.get("context") != null){
				WHERE("lm.context = #{context}");
			}
			if(params.get("status") != null){
				WHERE("lm.status = #{status}");
			}
			WHERE("lm.status != '9'");
		}}.toString();
	}
	
	public String findLeavingmessageCount(final Map<String, Object> params) {
		return new SQL(){{
			SELECT("count(0)");
			FROM("leavingmessage lm");
			LEFT_OUTER_JOIN("t_user t on lm.userid = t.id");
			WHERE("lm.createdate > #{contextDateBegin}");
			WHERE("lm.createdate < #{contextDateEnd}");
			if(params.get("userName") != null){
				WHERE("t.nickname = #{userName}");
			}
			if(params.get("context") != null){
				WHERE("lm.context = #{context}");
			}
			if(params.get("status") != null){
				WHERE("lm.status = #{status}");
			}
		}}.toString();
	}
}
